package com.sunriz.motordrive.controller.photovoltaic;

import com.sunriz.motordrive.domain.DAO.PvHcInfoDAO;
import com.sunriz.motordrive.domain.DTO.Result;
import com.sunriz.motordrive.server.photoVoltaic.HcInfoConfigServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: HcInfoConfig
 * Package: com.sunriz.motordrive.controller.photoVoltatic.hc
 * Description:
 *  配置文件数据
 * @Author BuTang
 * @Create 2024/8/14 11:10
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/photovoltaic/info")
public class HcInfoConfigController {

    @Resource
    HcInfoConfigServer hcInfoConfigServer;

    @PostMapping("/addData")
    public Result addData(@RequestBody PvHcInfoDAO pvHcInfo){
        hcInfoConfigServer.addData(pvHcInfo);
        return Result.success();
    }

    @GetMapping("/getByAddress")
    public Result getInfoByAddress(@RequestParam int address){
        return Result.success(hcInfoConfigServer.getByAddress(address));
    }


    @DeleteMapping("/deleteByAddress")
    public Result deleteByAddress(@RequestParam int address){
        log.info("删除address为 “{}“ 的寄存器",address);
        hcInfoConfigServer.deleteByAddress(address);
        return Result.success();
    }

    @PutMapping("/changeData")
    public Result changeData(@RequestBody PvHcInfoDAO pvHcInfo){
        hcInfoConfigServer.changeData(pvHcInfo);
        return Result.success();
    }

    @GetMapping("/getAllConfig")
    public Result<List<PvHcInfoDAO>> getAllConfig(){
        log.info("获取光伏hc寄存器配置");
        return Result.success(hcInfoConfigServer.getAllConfig());
    }


}
